<template>
    <div>
        <h1>科室修改</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">科室名称</td>
                    <td>
                        <input type="text" v-model="qureyInfo.departmentName" />
                    </td>
                </tr>
                <tr>
                    <td align="right">科室人数</td>
                    <td>
                        <textarea v-model="qureyInfo.departmentNumber"></textarea>
                    </td>
                </tr>
                <tr>
                    <td align="right">科室介绍</td>
                    <td>
                        <input type="text" v-model="qureyInfo.departmentDesc" />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="修改" class="btn btn-primary" @click="Ok" />
                    </td>
                </tr>
            </tbody>

        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

onMounted(() => {
    fan();
})

let qureyInfo: any = reactive({
    "departmentName": "",
    "departmentNumber": '',
    "departmentDesc": "",
})
const Ok = () => {
    axios({
        url: '/api/Ward/UpdateDepartment',
        method: 'put',
        data: qureyInfo,
    })
        .then(res => {
            if (res.data == -1) {
                alert("科室名称不能为空");
                return;
            }
            if (res.data > 0) {
                alert("修改成功");
                router.push('/departmomentList');
                return;
            }
            else {
                alert("修改失败");
                return;
            }
        })
        .catch(err => {

        })
}

const fan = () => {
    axios({
        url: '/api/Ward/GetDepartmentItem',
        method: 'get',
        params: { id: route.query.id }
    })
        .then(res => {
            Object.assign(qureyInfo, res.data);
        })
        .catch(err => {

        })
}

</script>

<style scoped></style>